import Vue from 'vue'
import Router from 'vue-router'
// import vuex from 'vuex'

Vue.use(Router)
// Vue.use(vuex)

const projectName = "时间胶囊";

const router = new Router({
    routes: [
        {
            path: '/',
            redirect: '/timeCaps'
        },
        {
            meta: {
                desc: '登录引导',
                title: `Hi，${projectName}`,
            },
            path: '/login',
            name: 'login',
            component: () =>
                import('@/page/login/login'),
        },
        {
            meta: {
                desc: '登录',
                title: `Hi，欢迎回到${projectName}`,
            },
            path: '/logindo',
            name: 'logindo',
            component: () =>
                import('@/page/login/logindo'),
        },
        {
            meta: {
                desc: '注册',
                title: `Hi，欢迎加入${projectName}`,
            },
            path: '/register',
            name: 'register',
            component: () =>
                import('@/page/login/register'),
        },
        {
            meta: {
                title: `${projectName}`,
            },
            path: '/timeCaps',
            name: 'timeCaps',
            component: () =>
                import('@/page/index')
        },
        {
            meta: {
                title: '页面找不到了~',
            },
            path: '/404',
            component: () =>
                import('@/page/errorPage/404')
        },
        {
            path: '*',
            redirect: '/404'
        }
    ]
});

router.beforeEach((to, from, next) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title;
    }
    next();
})

export default router;
